import { http } from '@/utils/http.ts'
// create.vue
import type { CreateData, CreateOrderParams } from '@/types/order'

export const getOrderPreApi = () => {
  return http<CreateData>({
    method: 'GET',
    url: '/member/order/pre',
  })
}

export const getOrderPreNowApi = (data: { skuId: string; count: string; addressId?: string }) => {
  return http<CreateData>({
    method: 'GET',
    url: '/member/order/pre/now',
    data,
  })
}
export const submitOrderApi = (data: CreateOrderParams) => {
  return http<{ id: string }>({
    method: 'POST',
    url: '/member/order',
    data,
  })
}

export const getRepurchaseOrderApi = (id: string) => {
  return http<CreateData>({
    method: 'GET',
    url: '/member/order/repurchase/' + id,
  })
}

// detail.vue
import type { DetailOrderLogistic, DetailOrderResult } from '@/types/order'

export const getOrderDetailApi = (orderId: string) => {
  return http<DetailOrderResult>({
    method: 'GET',
    url: '/member/order/' + orderId,
  })
}

export const payMockApi = (data: { orderId: string }) => {
  return http({
    method: 'GET',
    url: '/pay/mock',
    data,
  })
}

export const payOrderApi = (data: { orderId: string }) => {
  return http<WechatMiniprogram.RequestPaymentOption>({
    method: 'GET',
    url: '/pay/wxPay/miniPay',
    data,
  })
}

/**
 * 模拟发货-内测版
 * @description 在DEV环境下使用，仅在订单状态为待发货时，可模拟发货，调用后订单状态修改为待收货，包含模拟物流。
 * @param id 订单id
 */
export const mockConsignmentApi = (id: string) => {
  return http({
    method: 'GET',
    url: `/member/order/consignment/${id}`,
  })
}

// 确认收货
export const confirmReceiptApi = (id: string) => {
  return http<DetailOrderResult>({
    method: 'PUT',
    url: `/member/order/${id}/receipt`,
  })
}

/**
 * 获取订单物流
 * @description 仅在订单状态为待收货，待评价，已完成时，可获取物流信息。
 * @param id 订单id
 */
export const getOrderLogisticsApi = (id: string) => {
  return http<DetailOrderLogistic>({
    method: 'GET',
    url: `/member/order/${id}/logistics`,
  })
}

// 删除订单
export const delOrderApi = (data: { ids: string[] }) => {
  return http({
    method: 'DELETE',
    url: '/member/order',
    data,
  })
}

// 取消订单
export const cancelOrderApi = (id: string, data: { cancelReason: string }) => {
  return http<DetailOrderResult>({
    method: 'PUT',
    url: `/member/order/${id}/cancel`,
    data,
  })
}

import { httpLong } from '@/utils/http.ts'
import type { ListOrderParams, ListOrderResult } from '@/types/order'
// list.vue
/**
 * 获取订单列表
 * @param data orderState 订单状态
 */
export const getOrderListApi = (data: ListOrderParams) => {
  return httpLong<ListOrderResult>({
    method: 'GET',
    url: '/member/order',
    data,
  })
}
